function debounce(fn, interval) {
  let timer = null

  return function () {
    if (timer) clearTimeout(timer)
    timer = setTimeout(() => {
      fn.apply(this, arguments) //这是使用apply是保证this的指向是对的
      // console.log(...arguments);
    }, interval)
  }
}

function handle() {
  console.log('test');
}

const debounceHandle = debounce(handle, 1000)

debounceHandle(1)
debounceHandle(2)
debounceHandle(3)
debounceHandle(4)
debounceHandle(5)
// debounceHandle(6)